<?php
namespace app\admin\controller\index;
use think\Request;
use app\admin\server\index\Login as loginServer;
use app\admin\common;
use think\facade\Cache;
use app\admin\ControllerBase;
/**
 * @title 后台登陆类
 * 
 */
class Login extends ControllerBase{
//	protected $request;
//	public static $server;
    protected $o_String;
    public function __construct(request $request)
    {
    	$this->REQUEST=$request;
        self::$s_server=new loginServer($request);
    }
    /**
     * @title 获取图片验证码
     * @return string code - [0成功][201失败]
     * @return string data.image - 返回一个Url这个Url就是图片地址
     */
    public function selectCode(){
    	return $this->commonFunction(__function__);
    }

	public function loginPasswd(){
		//1.检测数据
		$checkFlag = $this->checkVailDate(\app\admin\validate\Login::class, __function__);
        if (!$checkFlag) {
            return common::return_json($checkFlag, $this->ERROR, $this->CODE);
        }
		return $this->commonFunction(__function__);
	}
		/**
	 * @title 获取验证码
	 * @param string mobile 18583220363 手机号码
	 */
	public function getCode(){
		//1.检测数据
		$checkFlag = $this->checkVailDate(\app\admin\validate\Login::class, __function__);
        if ($checkFlag == false) {
            return common::return_json($checkFlag, $this->ERROR, $this->CODE);
        }
        $this->requestLog(__function__, $this->REQUEST->param(), '帐号密码登陆');
		return $this->commonFunction(__function__);
	}
	/**
	 * @title 手机验证码登陆
	 * @param string mobile 18583220363 手机号码 
	 * @param string code 123456 验证码
	 */
	public function loginMobile(){
		//1.检测数据
		$checkFlag = $this->checkVailDate(\app\admin\validate\Login::class, __function__);
        if ($checkFlag == false) {
            return common::return_json($checkFlag, $this->ERROR, $this->CODE);
        }
        $this->requestLog(__function__, $this->REQUEST->param(), '手机验证码登陆');
		return $this->commonFunction(__function__);
	}
	/**
	 * @title 退出登陆前端直接把存储的token给干掉就行了
	 */
	public function loginOut(){
		Cache::clear();
		$loginUrl=$_SERVER['REQUEST_SCHEME']."://".$_SERVER['HTTP_HOST']."/admin/index.Login/login";
		header('Location:'.$loginUrl);
	}
	 
}
?>